
void config_pin_fun_init(void)
{
	unsigned int buf;
    unsigned long addr = 0xbfe10000;
	//配置通用寄存器0地址，0xbfe10420
	buf = *(volatile unsigned int *)(addr + 0x0420);
	//tgt_printf("-------0x0420 reg:0x%x \n",buf);
#ifdef PINSEL_GMAC1
	buf |=  (1 << 3);
#else
	buf &= ~(1 << 3);
#endif
#ifdef PINSEL_HDA
	buf |=  (1 << 4);
#else
	buf &= ~(1 << 4);
#endif
#ifdef PINSEL_I2S
	buf |=  (1 << 6);
#else
	buf &= ~(1 << 6);
#endif
#ifdef PINSEL_LIO
	buf |=  (1 << 7);
#else
	buf &= ~(1 << 7);
#endif
#ifdef PINSEL_SATA
	buf |=  (1 << 8);
#else
	buf &= ~(1 << 8);
#endif
#ifdef PINSEL_NAND
	buf |=  (1 << 9);
#else
	buf &= ~(1 << 9);
#endif
#ifdef PINSEL_I2C0
	buf |=  (1 << 10);
#else
	buf &= ~(1 << 10);
#endif
#ifdef PINSEL_I2C1
	buf |=  (1 << 11);
#else
	buf &= ~(1 << 11);
#endif
#ifdef PINSEL_PWM0
	buf |=  (1 << 12);
#else
	buf &= ~(1 << 12);
#endif
#ifdef PINSEL_PWM1
	buf |=  (1 << 13);
#else
	buf &= ~(1 << 13);
#endif
#ifdef PINSEL_PWM2  //LCD背光 暂不做初始化，沿用PMON，暂驱动不支持设备树设置默认背光值
	buf |=  (1 << 14);
#else
	buf &= ~(1 << 14);
#endif
#ifdef PINSEL_PWM3
	buf |=  (1 << 15);
#else
	buf &= ~(1 << 15);
#endif
#ifdef PINSEL_CAN0
	buf |=  (1 << 16);
#else
	buf &= ~(1 << 16);
#endif
#ifdef PINSEL_CAN1
	buf |=  (1 << 17);
#else
	buf &= ~(1 << 17);
#endif
#ifdef PINSEL_SDIO
	buf |=  (1 << 20);
#else
	buf &= ~(1 << 20);
#endif
	//tgt_printf("-------0x0420 reg:0x%x \n",buf);
	*(volatile unsigned int *)(addr + 0x0420) = buf;

	//配置通用寄存器1地址，0xbfe10428
	buf = *(volatile unsigned int *)(addr + 0x0428);
	//tgt_printf("-------0x0428 reg:0x%x \n",buf);

	buf |=  (PINSEL_UART0_FUN << 0);   //UART0不能复用成GPIO所以只需配模式

#ifdef PINSEL_UART1
	buf |=  (1 << 12);
	buf |=  (PINSEL_UART1_FUN << 4);
#else
	buf &= ~(1 << 12);
#endif

#ifdef PINSEL_UART2
	buf |=  (1 << 13);
	buf |=  (PINSEL_UART2_FUN << 8);
#else
	buf &= ~(1 << 13);
#endif
    //tgt_printf("-------0x0428 reg:0x%x \n",buf);
	*(volatile unsigned int *)(addr + 0x0428) = buf;

//配置通用寄存器2地址，0xbfe10430
	buf = *(volatile unsigned int *)(addr + 0x0430);
	//tgt_printf("-------0x0430 reg:0x%x \n",buf);

#ifdef PINSEL_DVO0
	buf |=  (1 << 1);
#else
	buf &= ~(1 << 1);
#endif
#ifdef PINSEL_DVO1
	buf |=  (1 << 4);
#else
	buf &= ~(1 << 4);
#endif
#ifdef PINSEL_CAM
	buf |=  (1 << 5);
#else
	buf &= ~(1 << 5);
#endif
	//tgt_printf("-------0x0430 reg:0x%x \n",buf);
	*(volatile unsigned int *)(addr + 0x0430) = buf;
}


void platform_init(void)
{
	config_pin_fun_init();

	*(volatile unsigned int *)0xbfe10428 &= ~(1<<19); /*disable usb prefetch*/

#ifdef LCD_EN   //DVO0显示输出控制
	*(volatile int *)(0xbfe10500 + DVO0_PW_GPIO/32*4) &= ~(1 << (DVO0_PW_GPIO%32));
	*(volatile int *)(0xbfe10510 + DVO0_PW_GPIO/32*4) |=  (1 << (DVO0_PW_GPIO%32));
	*(volatile int *)(0xbfe10500 + DVO0_BL_GPIO/32*4) &= ~(1 << (DVO0_BL_GPIO%32));
	*(volatile int *)(0xbfe10510 + DVO0_BL_GPIO/32*4) |=  (1 << (DVO0_BL_GPIO%32));
	*(volatile int *)(0xbfe10500 + DVO0_RST_GPIO/32*4) &= ~(1 << (DVO0_RST_GPIO%32));
	*(volatile int *)(0xbfe10510 + DVO0_RST_GPIO/32*4) |=  (1 << (DVO0_RST_GPIO%32));
#endif

	*(volatile int *)0xbfe10440 = 0x1a3a0df9;   //USB PHY0/1 配置寄存器
	/*otg vbus*/
	//*(volatile int *)0xc0000000 |= 6;
}

unsigned long long get_ticks(void)
{
	static 	unsigned int timebase_h;
	static  unsigned int timebase_l;

	unsigned int now = read_c0_count();

	/* increment tbu if tbl has rolled over */
	if (now < timebase_l)
		timebase_h++;
	timebase_l = now;
	return ((unsigned long long)timebase_h << 32) | timebase_l;
}

unsigned int rand_r(unsigned int *seedp)
{
	*seedp ^= (*seedp << 13);
	*seedp ^= (*seedp >> 17);
	*seedp ^= (*seedp << 5);
	return *seedp;
}

void net_random_ethaddr(unsigned char *addr)
{
	int i;
	unsigned int seed = get_ticks();

	for (i = 0; i < 6; i++)
	{
		addr[i] = rand_r(&seed);
	}

	addr[0] &= 0xfe;	/* clear multicast bit */
	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
}